# -*- coding: utf-8 -*-
'''
Created on Feb 2, 2013

@author: LONG HOANG GIANG
'''

from Model.storymodelv3 import StoryModel
import os
import sqlite3 as db

    
class Convert():
    
    def fromv2tov3(self, src, dest):
        connectionv2 = db.connect(src)
        c1 = connectionv2.cursor()
        c1.execute("select * from udv_story")
        chapters = c1.fetchall()
        c2 = StoryModel(dest)
        c2.open(True)
        for chapter in chapters:
            catId = chapter[1]
            title = chapter[2]
            detail = chapter[3]
            print title
            c2.add_story(title, detail, catId)
        c1.execute("select * from udv_category")
        categories = c1.fetchall()
        for cat in categories:
            c2.add_category(cat[1], cat[2])
        c2.close()
        c1.close()
        
if __name__ == '__main__':    

    src = '/longhoanggiang/database/10vancauhoivisao'
    des = '/longhoanggiang/database/_10vancauhoivisao'

    convert = Convert()
    convert.fromv2tov3(src, des)
    
    print '> Finished'
    os._exit(1)